<%@ page contentType="text/html; charset=iso-8859-1" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ page import="com.iMusic.businessLogicLayer.Account" %>
<%@ page import="com.iMusic.businessLogicLayer.Staff" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>iMusic</title>

<script>
function validateForm()
{
var x=document.forms["Login"]["username"].value;
if (x==null || x=="")
  {
  alert("Username must be filled out.");
  return false;
  }
var y=document.forms["Login"]["password"].value;
if (y==null || y=="")
  {
  alert("Password must be filled out.");
  return false;
  }
if (y.length < 4)
  {
	alert("Password must have at least 4 characters.");
	return false;
  }
}
</script>

</head>
<body>
<%
String error=request.getParameter("error");
if(error==null || error=="null"){
 error="";
}

%>
		<table
			style="text-align: left; width: 100%; background-color: rgb(204, 204, 204);"
			border="0" cellpadding="2" cellspacing="2">
			<tbody>
				<tr>
					<td style="vertical-align: middle; width: 424px;"><big
						style="font-weight: bold;"><big><big>iMusic</big></big></big><br>
						<big style="font-weight: bold;"><big>Online Music
								Store</big></big></td>
					<td
						style="vertical-align: middle; text-align: right; width: 365px;">
						<%
							String username = null;
							Account account = (Account) request.getSession().getAttribute("Account");
							Staff staff = (Staff) request.getSession().getAttribute("Staff");;
							if (account != null) {
								username = account.getUsername();
							}
							else if (staff != null) {
								username = staff.getUsername();
							}
							
							if (username==null || username=="null" || !error.equals("")) {
						%>
							<form style="vertical-align: middle; text-align: right; " target="_top" action="Login" method="post" name="Login" onsubmit="return validateForm()">
							Username: <input name="username"><br>
							Password:&nbsp;	<input name="password" type="password"><br>
							<input value="Login" type="submit"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
							</form>
						
							New to iMusic? <a href="createAccountFS.jsp" target="_top">Sign-up!</a>&nbsp;
						<% 
							}
							else {
						%>
								<b><i><%=username%></i></b>
								<br>
								
								<%
									if (account != null) {
								%>
										<form style="vertical-align: middle; text-align: right; " action="SearchOrder" target="_top" method="post" name="SearchOrder">
										<input value="Order History" type="submit"> </form>
								<%																
									}
									else {
										if (staff != null) {
								%>
											Administration area<br>
								<%
										}
									}
								%>
								
								
								<form style="vertical-align: middle; text-align: right; " action="Logout" target="_top" method="post" name="Logout">
								<input value="Logout" type="submit"> </form>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
								<br>
						<%		
							}
						%>
					</td>
				</tr>
			</tbody>
		</table>	
</body>
</html>